from langchain.document_loaders import PyPDFLoader
from langchain.indexes.vectorstore import VectorstoreIndexCreator
from dotenv import load_dotenv

import os
os.environ["OPENAI_API_KEY"] = "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"


p = 'demo.pdf'
print(0)
loader = PyPDFLoader(p)
print(1)
index = VectorstoreIndexCreator().from_loaders([loader])
print(2)
ans = index.query_with_sources("合同", chain_type="map_reduce")

print(ans)